//
// Created by KangLe on 2017/5/6.
//


#include "SelectImgScoreUtil.h"
#include "MyLog.h"

#define PF(a)  ((a)*(a))//平方

jlong Java_com_uniubi_selectimgscore_SelectImgScoreUtil_getImageScore
(JNIEnv *env, jobject obj, jbyteArray data, jint w, jint h){

    LOGD("log.d 这是Jni中的log: ()");
    jbyte* bBuffer = (*env)->GetByteArrayElements(env,data,0);
    unsigned char* buf=(unsigned char*)bBuffer;
//    for(int i=0; i < w; i++ ) {

//    }
//    int cc = 123;
    long score = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            score +=  PF(buf[i * w + j + 1] - buf[i * w + j]) +
                    PF(buf[(i + 1) * w + j] - buf[i * w + j]);
        }
    }
    (*env)->ReleaseByteArrayElements(env,data, bBuffer, 0);
    return score;
}
/**
 * 检测清晰度
 *//*

private byte[] checkClarity() {
    long start = System.currentTimeMillis();
    int max = 0;
    byte[] bitmapYuv = null;
    for (byte[] bytes : mImg) {
        int score = 0;
        for (int i = 0; i < FaceCoreConstant.videoHigh; i++) {
            for (int j = 0; j < FaceCoreConstant.videoWidth; j++) {
                score += Math.pow(bytes[i * FaceCoreConstant.videoWidth + j + 1] - bytes[i * FaceCoreConstant.videoWidth + j], 2) +
                         Math.pow(bytes[(i + 1) * FaceCoreConstant.videoWidth + j] - bytes[i * FaceCoreConstant.videoWidth + j], 2);
            }
        }
        if (score >= max) {
            max = score;
            bitmapYuv = bytes;
        }
    }
    byte[] img = new byte[FaceCoreConstant.videoWidth * FaceCoreConstant.videoHigh * 2];
    System.arraycopy(bitmapYuv, 0, img, 0, bitmapYuv.length);
    LogPrint.d("筛选最清晰耗时：" + (System.currentTimeMillis() - start));
    return img;
}*/
